package com.restaurant.application.qrcode.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;
import com.nebutown.generation.basictype.UID;

import java.util.List;

public class QrCodeData implements PickableBean {

    public static final String FN_ID = "id";
    public static final String FN_QRURL = "qrUrl";
    public static final String FN_OWNERID = "ownerId";
    public static final String FN_CONTAINER = "container";
    public static final String FN_REMARK = "remark";
    public static final String FN_HASTIMEOUT = "hasTimeOut";
    public static final String FN_PERIOD = "period";
    public static final String FN_CREATETIME = "createTime";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_ID,
            FN_QRURL,
            FN_OWNERID,
            FN_CONTAINER,
            FN_REMARK,
            FN_HASTIMEOUT,
            FN_PERIOD,
            FN_CREATETIME);

    private String id;
    private String qrUrl;
    private UID ownerId;
    private UID container;
    private String remark;
    private Boolean hasTimeOut;
    private Integer period;
    private Long createTime;

    public QrCodeData(String id, String qrUrl, UID ownerId, UID container, String remark, Boolean hasTimeOut, Integer period, Long createTime) {
        setId(id);
        setQrUrl(qrUrl);
        setOwnerId(ownerId);
        setContainer(container);
        setRemark(remark);
        setHasTimeOut(hasTimeOut);
        setPeriod(period);
        setCreateTime(createTime);
    }

    public QrCodeData() {
    }

    public QrCodeData duplicate() {
        QrCodeData result = new QrCodeData();
        result.id = this.id;
        result.qrUrl = this.qrUrl;
        result.ownerId = this.ownerId;
        result.container = this.container;
        result.remark = this.remark;
        result.hasTimeOut = this.hasTimeOut;
        result.period = this.period;
        result.createTime = this.createTime;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getId() {
        return id;
    }

    public void setId(String value) {
        this.id = value;
    }

    public QrCodeData withId(String value) {
        setId(value);
        return this;
    }

    public QrCodeData withId(String value, String defaultValue) {
        setId(value == null ? defaultValue : value);
        return this;
    }

    public String getQrUrl() {
        return qrUrl;
    }

    public void setQrUrl(String value) {
        this.qrUrl = value;
    }

    public QrCodeData withQrUrl(String value) {
        setQrUrl(value);
        return this;
    }

    public QrCodeData withQrUrl(String value, String defaultValue) {
        setQrUrl(value == null ? defaultValue : value);
        return this;
    }

    public UID getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(UID value) {
        this.ownerId = value;
    }

    public QrCodeData withOwnerId(UID value) {
        setOwnerId(value);
        return this;
    }

    public QrCodeData withOwnerId(UID value, UID defaultValue) {
        setOwnerId(value == null ? defaultValue : value);
        return this;
    }

    public UID getContainer() {
        return container;
    }

    public void setContainer(UID value) {
        this.container = value;
    }

    public QrCodeData withContainer(UID value) {
        setContainer(value);
        return this;
    }

    public QrCodeData withContainer(UID value, UID defaultValue) {
        setContainer(value == null ? defaultValue : value);
        return this;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String value) {
        this.remark = value;
    }

    public QrCodeData withRemark(String value) {
        setRemark(value);
        return this;
    }

    public QrCodeData withRemark(String value, String defaultValue) {
        setRemark(value == null ? defaultValue : value);
        return this;
    }

    public Boolean getHasTimeOut() {
        return hasTimeOut;
    }

    public void setHasTimeOut(Boolean value) {
        this.hasTimeOut = value;
    }

    public QrCodeData withHasTimeOut(Boolean value) {
        setHasTimeOut(value);
        return this;
    }

    public QrCodeData withHasTimeOut(Boolean value, Boolean defaultValue) {
        setHasTimeOut(value == null ? defaultValue : value);
        return this;
    }

    public Integer getPeriod() {
        return period;
    }

    public void setPeriod(Integer value) {
        this.period = value;
    }

    public QrCodeData withPeriod(Integer value) {
        setPeriod(value);
        return this;
    }

    public QrCodeData withPeriod(Integer value, Integer defaultValue) {
        setPeriod(value == null ? defaultValue : value);
        return this;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long value) {
        this.createTime = value;
    }

    public QrCodeData withCreateTime(Long value) {
        setCreateTime(value);
        return this;
    }

    public QrCodeData withCreateTime(Long value, Long defaultValue) {
        setCreateTime(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "id":
                return getId();
            case "qrUrl":
                return getQrUrl();
            case "ownerId":
                return getOwnerId();
            case "container":
                return getContainer();
            case "remark":
                return getRemark();
            case "hasTimeOut":
                return getHasTimeOut();
            case "period":
                return getPeriod();
            case "createTime":
                return getCreateTime();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof QrCodeData)) return false;
        return signature().equals(((QrCodeData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean QrCodeData has no signature defined, no hash code or equals possible.");
    }
}
